package org.jeecg.modules.logistics.dictionaries.user_dic.service.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.modules.logistics.dictionaries.user_dic.entity.UserDicInfo;
import org.jeecg.modules.logistics.dictionaries.user_dic.mapper.UserDicMapper;
import org.jeecg.modules.logistics.dictionaries.user_dic.service.IUserDicService;
import org.jeecg.modules.logistics.manage.hw_info.entity.HwInfo;
import org.jeecg.modules.logistics.manage.hw_info.mapper.HwInfoMapper;
import org.jeecg.modules.logistics.manage.hw_info.service.IHwInfoService;
import org.jeecg.modules.logistics.table.user_sf.entity.UserSf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2019/12/24  10:55
 */
//TODO user_sf       用户身份
@Service
@DS("freight")
public class UserDicServiceImpl implements IUserDicService {
    @Autowired
    UserDicMapper userDicMapper;

    @Override
    public UserDicInfo getUserDicInfo() {
        UserDicInfo userDicInfo = new UserDicInfo();
        userDicInfo.setUserSfList(userDicMapper.getAllUserSf());
        return userDicInfo;
    }

    @Override
    public int putUserDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "user_sf":
                UserSf userSf = (UserSf) jsonObj.get("data");
                return userDicMapper.PutUserSf(userSf);
            default:
                return 0;
        }
    }

    @Override
    public int delUserDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        int id = jsonObj.getInt("data");
        switch (dic) {
            case "user_sf":
                return userDicMapper.DelUserSf(id);
            default:
                return 0;
        }
    }

    @Override
    public int addUserDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "user_sf":
                UserSf userSf = (UserSf) jsonObj.get("data");
                return userDicMapper.AddUserSf(userSf);
            default:
                return 0;
        }
    }
}
